package controller

import (
	"blog/dao"
	"github.com/julienschmidt/httprouter"
	"html/template"
	"net/http"
)

/**

 */
func AdminCacheHandle(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	dao.CommonAction(r, w)

	guest := new(dao.GuestSession)
	//检查是否未登录
	if guest.Init(r).CheckIsLogin() == false {
		dao.RedirectPage(w, "Error", "未登录", "/admin/user/login", 503, 3)
		return
	}

	//渲染页面
	t, err := template.New("adminCache.html").Funcs(dao.FuncMap).ParseFiles("templates/adminCache.html", "templates/pub_inc.html", "templates/admin_inc.html")
	if err != nil {
		dao.LogError(err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	t.Execute(w, nil)
}

func AdminCacheUpdateHandle(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	dao.CommonAction(r, w)

	guest := new(dao.GuestSession)
	//检查是否未登录
	if guest.Init(r).CheckIsLogin() == false {
		dao.SendResult(w, dao.ERR_NO_LOGIN.Code, dao.ERR_NO_LOGIN.Message, nil)
		return
	}

	//写入数据缓存
	dao.InitPageConfig()
	dao.SendResult(w, dao.ERR_NONE.Code, dao.ERR_NONE.Message, nil)
}
